<?php


namespace app\common\service;


/**
 * 支付服务
 * Class AuthService
 * @package app\common\service
 */
class PayService
{

    public function submit($paytype,$payconfig,$amount,$orderId,$subject,$returnUrl=''){

        $paymethod = $payconfig['alias'];
        try {
            $notifyUrl = domain_url('/notify/' . $paymethod .'_'.$payconfig['id']. '.html');
            $payclass = "\\payment\\" . $paymethod . "\\" . $paymethod;
            $PAY = new $payclass();
            $params['return_url']= $returnUrl?$returnUrl:$notifyUrl;
            $params['notify_url']= $notifyUrl;
            $params['order_no'] = $orderId;
            $params['amount'] = $amount;
            $params['subject'] = $subject;
            $params['body'] = $subject;
            $params['pay_type'] = $paytype;
            $res = $PAY->submit($payconfig, $params);
            if (isset($res['data']['subjumpurl'])) {
                $subjumpurl=$res['data']['subjumpurl'];
                $ret['order_no'] = $orderId;
                $ret['subjump_url'] = $subjumpurl;
                $ret['qrcode'] = domain_url('/qrcode?str=' . urlencode($subjumpurl));//支付二维码
                return success('下单成功',$ret,0);
            }else{
                return $res;
            }
        } catch (\Exception $e) {
            return fail('调起支付失败'.$e->getMessage(),[],0);
        }
    }

}